<?php
namespace addon\cms\controller;

use app\common\controller\AddonAdminBase;
use tpfcore\Core;
//use tpfcore\helpers\Json;
//use tpfcore\base\SdkOauth;
//use think\Request;
// +----------------------------------------------------------------------
// | Author: yaoyihong <510974211@qq.com>
// +----------------------------------------------------------------------
/**
 * ============================================================================
 * 版权所有 2017-2077 tpframe工作室，并保留所有权利。
 * @link http://www.tpframe.com/
 * @copyright Copyright (c) 2017 TPFrame Software LLC
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！未经本公司授权您只能在不用于商业目的的前提下对程序代码进行修改和使用；
 * 不允许对程序代码以任何形式任何目的的再发布。
 * 机器人，持续更新中.
 * ============================================================================
 */
class Recycle extends AddonAdminBase
{
    public function index(){
      $where = ['isdelete'=>-1];
      if(isset($this->param['act']) && $this->param['act']=="search"){
        $search = $this->param;
        $this->assign('search',$search);
        if($search['cateid']!=0){
          $cIds=Core::loadModel('Category','frontend','logic')->getChildIds((int)$search['cateid']);
          $cIds[]=(int)$search['cateid'];
          $where['cateid']=['in',implode(',',$cIds)];
        }
        !empty($search['keyword']) ? $where['__POSTS__.title']=['like','%'.$search['keyword'].'%'] : '';
        $begin='';$end='';
        !empty($search['start_time']) ? $begin=strtotime($search['start_time']) : '';
        empty($search['end_time']) ? $end=time() : $end=strtotime($search['end_time']);
        if($begin && $end){
          $where['__POSTS__.datetime'] = ['between',"$begin,$end"];
        }
      }
      $this->addonTemplate('index',[
          'list'=>Core::loadAddonModel("Posts")->getPostsList(
              [
                "where"     =>$where, 
                "field"     =>"__POSTS__.*,c.title ctitle", 
                "order"     =>"__POSTS__.updatetime DESC", 
                "paginate"  =>["rows"=>15,"config"=>["query"=>$this->param]],
                "join"      =>['join' => "__CATEGORY__ c", 'condition' => "__POSTS__.cateid=c.id",'type' => 'left'],
              ]
          ),
          'categorys'=>Core::loadAddonModel("Category")->getTreeCategory($this->param)
      ]);
    }
    
    //删除 
    public function destory(){
      $this->jump(Core::loadAddonModel("Posts")->destory($this->param));
    }
    //还原
    public function restore(){
      $this->jump(Core::loadAddonModel("Posts")->restore($this->param));
    }
}
